package Registry;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class MyRegistry {
	
	private String fHost;
	private int fPort;
	
	public MyRegistry(String host, int port) {
		fHost = host;
		fPort = port;
	}
	
	public void start() {
		try {
			// Set up registry
			LocateRegistry.createRegistry(fPort);
			
			// Bind RegistryService
			MyRegistryService registryService = new MyRegistryService(fPort);
			Registry registry = LocateRegistry.getRegistry(null, fPort);
			registry.rebind("RegistryService", registryService);
			
			// Output
			System.out.println("[REGISTRY] Registry started on host " + fHost + " and port " + fPort);

		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}
}
